/**
 * CaddieFileRecorder.java 21 juil. 07
 *
 * Copyright (c) 2007 windu.2b <jcaddie@windu2b.org>. All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.windu2b.jcaddie.io;

import java.io.*;
import java.util.*;

import org.windu2b.jcaddie.io.sgbd.*;
import org.windu2b.jcaddie.model.*;
import org.windu2b.jcaddie.swing.*;

/**
 * @author windu.2b
 * @version 0.2
 */
public class CaddieFileRecorder implements CaddieRecorder
{
	private static ResourceBundle	resource;

	
	
	public CaddieFileRecorder()
	{
		resource = ResourceBundle.getBundle( CaddieController.class.getName() );
	}




	/**
	 * @see org.windu2b.jcaddie.model.CaddieRecorder#exists(java.lang.String)
	 */
	public boolean exists( String name ) throws RecorderException
	{
		return new File( name ).exists();
	}




	/**
	 * @see org.windu2b.jcaddie.model.CaddieRecorder#writeCaddie(org.windu2b.jcaddie.model.Caddie,
	 *      java.lang.String)
	 */
	public void writeCaddie( Caddie caddie, String fileName )
	        throws RecorderException
	{
		HSQLDBManager dbManager = HSQLDBManager.getInstance( fileName, caddie );
		try
		{
			dbManager.createDatabase( fileName );
			dbManager.insertCaddie();
		}
		catch ( HSQLDBException e )
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new RecorderException( e );
		}
		/*
		 * try { out = new CaddieOutputStream( new FileOutputStream( fileName ) );
		 * out.writeCaddie( caddie ); } catch ( IOException ex ) { throw new
		 * RecorderException( String.format( resource .getString( "saveError" ),
		 * fileName ), ex ); } finally { try { if ( out != null ) out.close(); }
		 * catch ( IOException ex ) { throw new RecorderException(
		 * String.format( resource .getString( "cannotCloseError" ), fileName ),
		 * ex ); } }
		 */
	}




	/**
	 * @see org.windu2b.jcaddie.model.CaddieRecorder#readCaddie(java.lang.String)
	 */
	public Caddie readCaddie( String name ) throws RecorderException
	{
		/*
		 * CaddieInputStream in = null; try { in = new CaddieInputStream( new
		 * FileInputStream( name ) );
		 * 
		 * Caddie caddie = in.readCaddie(); return caddie; } catch ( IOException
		 * ex ) { throw new RecorderException( String.format( resource
		 * .getString( "readError" ), name ), ex ); } catch (
		 * ClassNotFoundException ex ) { throw new RecorderException(
		 * String.format( resource .getString( "missingClasseError" ), name ),
		 * ex ); } finally { try { if ( in != null ) { in.close(); } } catch (
		 * IOException ex ) { throw new RecorderException( String.format(
		 * resource .getString( "cannotCloseError" ), name ), ex ); } }
		 */
		return null;
	}
}